﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;

namespace XiDainChangAn.OA.WF
{

    public sealed class Wait4InputDataActivity<T> : NativeActivity//想让工作流停下来，换成NativeActivity
    {
        // 定义一个字符串类型的活动输入参数
        public InArgument<string> InBookmarkName { get; set; }

        public OutArgument<T> OutPutData { get; set; }

        /// <summary>
        /// 重写
        /// </summary>
        protected override bool CanInduceIdle
        {
            get
            {
                return true;
            }
        }

        // 如果活动返回值，则从 CodeActivity<TResult>
        // 派生并从 Execute 方法返回该值。
        protected override void Execute(NativeActivityContext context)
        {
            // 获取 书签 输入参数的运行时值
            string text = context.GetValue(this.InBookmarkName);




            //让工作流“停下来”
            context.CreateBookmark(text, new BookmarkCallback(MethodCallBack));
        }

        /// <summary>
        /// 回调函数
        /// </summary>
        /// <param name="context"></param>
        /// <param name="bookmark"></param>
        /// <param name="value"></param>
        private void MethodCallBack(NativeActivityContext context, Bookmark bookmark, object value)
        {
            context.SetValue(OutPutData, (T)value);
        }
    }
}
